package com.sc.nft.util;

import cn.hutool.core.lang.UUID;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;

/**
 * @Author laodeng
 * @Created 2023/1/11 下午2:00
 */
public class TraceContext {
    public static final String TRACE_ID_KEY = "traceId";

    public static void setTraceId(String traceId) {
        if (StringUtils.isNotEmpty(traceId)) {
            MDC.put(TRACE_ID_KEY, traceId);
        }
    }

    public static String getTraceId() {
        String traceId = MDC.get(TRACE_ID_KEY);
        return traceId == null ? "" : traceId;
    }

    public static void removeTraceId() {
        MDC.remove(TRACE_ID_KEY);
    }

    public static void clearTraceId() {
        MDC.clear();
    }

    public static String genTraceId() {
        return UUID.randomUUID().toString().replace("-", "");
    }


}
